package com.heima.admin.controller.v1;

import com.heima.admin.service.AdChannelService;
import com.heima.apis.admin.AdChannelControllerApi;
import com.heima.model.admin.dtos.AdChannelDto;
import com.heima.model.admin.pojos.AdChannel;
import com.heima.model.common.dtos.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("/api/v1/channel")
@Api(tags = "频道管理")
public class AdChannelController implements AdChannelControllerApi {

    @Autowired
    AdChannelService adChannelService;

    //新增频道
    @PostMapping("/save")
    @Override
    public ResponseResult insert( @RequestBody  AdChannel adChannel) {
        return adChannelService.insert(adChannel);
    }

    //查询频道列表带分页
     //@param dto 查询条件

    @ApiOperation(value = "查询频道列表带分页")
    @Override
    @PostMapping("/list")
    public ResponseResult findByNameAndPage(@RequestBody AdChannelDto dto) {
        return adChannelService.findByNameAndPage(dto);
    }

    // 修改频道&频道状态

    @PostMapping("/update")
    @Override
    public ResponseResult update(@RequestBody AdChannel adChannel) {
        return adChannelService.update(adChannel);
    }

    // 根据id删除频道

    @GetMapping("/del/{id}")
    @Override
    public ResponseResult deleteById(@PathVariable("id") Integer id) {
        return adChannelService.deleteById(id);
    }
}
